<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="条码编号" prop="dvcNo">
        <el-input
          v-model="queryParams.dvcNo"
          placeholder="请输入条码编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
          style="width:240px;"
        />
      </el-form-item>
      <el-form-item label="创建时间">
          <el-date-picker
                  v-model="dateRange"
                  size="small"
                  style="width: 350px"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  type="datetimerange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
          </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:HisHandCmdWeight:edit']"
        >详情</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:HisHandCmdWeight:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="HisHandCmdWeightList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="ID" align="center" prop="id" /> -->
      <el-table-column label="操作" align="center" width="100" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:HisHandCmdWeight:edit']"
          >详情</el-button>
        </template>
      </el-table-column>
      <el-table-column label="作业名称" align="center" prop="cmdName" width="100" />
      <el-table-column label="条码编号" align="center" prop="dvcNo" min-width="120"/> 
      <el-table-column label="回传信息" align="center" prop="cmd" min-width="320" :show-overflow-tooltip="true" />
      <!-- <el-table-column label="标识" align="center" prop="dealFlag" :formatter="dealFlagFormat" /> -->
      <el-table-column label="创建时间" align="center" prop="creaTime" width="160">
          <template slot-scope="scope">
              <span>{{ parseTime(scope.row.creaTime) }}</span>
          </template>
      </el-table-column>
      
      <el-table-column label="更新时间" align="center" prop="updateTime" width="160">
          <template slot-scope="scope">
              <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
      </el-table-column>
      
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改称重回传对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="作业名称" prop="cmdName">
          <el-input v-model="form.cmdName" placeholder="请输入作业名称" />
        </el-form-item>
        <el-form-item label="条码编号" prop="dvcNo">
          <el-input v-model="form.dvcNo" placeholder="请输入条码编号" />
        </el-form-item>
        <el-form-item label="回传信息" prop="cmd">
          <el-input type="textarea" v-model="form.cmd" placeholder="请输入回传信息" />
        </el-form-item>
      </el-form>
      <!-- <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div> -->
    </el-dialog>
  </div>
</template>

<script>
import { listHisHandCmdWeight, getHisHandCmdWeight, delHisHandCmdWeight, addHisHandCmdWeight, updateHisHandCmdWeight, exportHisHandCmdWeight } from "@/api/system/HisHandCmdWeight";

export default {
  name: "HisHandCmdWeight",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 称重回传表格数据
      HisHandCmdWeightList: [],
        // 日期范围
        dateRange: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // ID字典
      idOptions: [],
      // 条码编号字典
      dvcNoOptions: [],
      // 作业名称字典
      cmdNameOptions: [],
      // 回传信息字典
      cmdOptions: [],
      // 创建时间字典
      creaTimeOptions: [],
      // 标识字典
      dealFlagOptions: [],
      // 更新时间字典
      updateTimeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dvcNo: null,
        cmdName: null,
        cmd: null,
        creaTime: null,
        dealFlag: null,
        updateTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("${column.dictType}").then(response => {
      this.idOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.dvcNoOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.cmdNameOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.cmdOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.creaTimeOptions = response.data;
    });
    this.getDicts("task_identification").then(response => {
      this.dealFlagOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.updateTimeOptions = response.data;
    });
  },
  methods: {
    /** 查询称重回传列表 */
    getList() {
      this.loading = true;
              listHisHandCmdWeight(this.addDateRange(this.queryParams, this.dateRange)).then(
        response => {
        this.HisHandCmdWeightList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // ID字典翻译
    idFormat(row, column) {
      return this.selectDictLabel(this.idOptions, row.id);
    },
    // 条码编号字典翻译
    dvcNoFormat(row, column) {
      return this.selectDictLabel(this.dvcNoOptions, row.dvcNo);
    },
    // 作业名称字典翻译
    cmdNameFormat(row, column) {
      return this.selectDictLabel(this.cmdNameOptions, row.cmdName);
    },
    // 回传信息字典翻译
    cmdFormat(row, column) {
      return this.selectDictLabel(this.cmdOptions, row.cmd);
    },
    // 创建时间字典翻译
    creaTimeFormat(row, column) {
      return this.selectDictLabel(this.creaTimeOptions, row.creaTime);
    },
    // 标识字典翻译
    dealFlagFormat(row, column) {
      return this.selectDictLabel(this.dealFlagOptions, row.dealFlag);
    },
    // 更新时间字典翻译
    updateTimeFormat(row, column) {
      return this.selectDictLabel(this.updateTimeOptions, row.updateTime);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dvcNo: null,
        cmdName: null,
        cmd: null,
        creaTime: null,
        dealFlag: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加称重回传";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getHisHandCmdWeight(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改称重回传";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHisHandCmdWeight(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addHisHandCmdWeight(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除称重回传编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delHisHandCmdWeight(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有称重回传数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportHisHandCmdWeight(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
